Repository navigation
Implement Roc codegen backend and runner support (#1964) - #12465
Conversation
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 10 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
…script-support # Conflicts: # pkgs/mcpx/internal/cli/commands.go # pkgs/mcpx/internal/cli/flagindex_generated.go # pkgs/mcpx/plugin/core/ops.gen.ts
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c9443d90d1
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| fmt.Fprintf(&b, " payload = { server: %s, tool: %s, args }\n", rocString(fn.server), rocString(fn.tool)) | ||
| b.WriteString(" body = Json.to_str_try(payload) ? |_err| TransportError(\"mcpx request encoding failed\")\n call!(body)\n}\n\n") |
There was a problem hiding this comment.
Restore original argument keys before JSON encoding
For schemas containing properties such as a-b, if, or colliding names like a-b and a_b, rocInputFields renames the fields, but this payload serializes the renamed record directly. The daemon consequently receives keys such as a_b, if_, and a_b_2 instead of the schema's original keys, causing required arguments to be missing or values to reach the wrong property. Preserve the original-to-generated field mapping and use the original keys when constructing the JSON request.
Useful? React with 👍 / 👎.
| case "boolean": | ||
| typ = "Bool" | ||
| } | ||
| fields = append(fields, uniqueRocIdent(rocIdent(k, false), usedNames)+" : "+typ) |
There was a problem hiding this comment.
Preserve omission semantics for optional arguments
When a tool schema has optional properties, every property is nevertheless emitted as a mandatory record field, and the complete record is serialized into the request. A caller therefore cannot omit an optional argument to use the server's default or leave a setting unchanged; supplying an empty string, zero, or false is not equivalent to omission. Read the schema's required set and provide an argument representation and encoder that can leave optional keys out of the payload.
Useful? React with 👍 / 👎.
| if len(fields) == 0 { | ||
| return []string{"_unit : {}"} |
There was a problem hiding this comment.
Encode an empty object for tools without arguments
For a tool whose input schema has no properties, the generated signature requires an artificial _unit field. Because the wrapper serializes args unchanged, the request contains {"_unit":{}} rather than {}. A no-argument tool with additionalProperties:false will reject that request. Keep any unit value needed by the Roc call interface separate from the wire arguments and encode an empty object for this case.
Useful? React with 👍 / 👎.
| bin, err := exec.LookPath("roc") | ||
| if err != nil { | ||
| return nil, errors.New("runner: roc binary not found on PATH for a Roc script") |
There was a problem hiding this comment.
Defer Roc lookup when the devshell supplies the compiler
When script.devshell=flake:<ref> provides Roc but the host has no roc executable, this lookup rejects .roc files and explicitly selected Roc snippets before execution reaches the devshell wrapper in runDispatched. This prevents using the configured development environment to supply the compiler, despite the devshell-owned PATH behavior documented in docs/runtimes.md:59. Allow the unresolved roc invocation through for flake environments, as the JavaScript dispatch path already does.
Useful? React with 👍 / 👎.
| b.WriteString("call! = |body| {\n") | ||
| b.WriteString(" endpoint = match Env.var_str!(\"MCPX_ENDPOINT\") {\n Ok(value) => value\n Err(_) => default_endpoint\n }\n") | ||
| b.WriteString(" session = match Env.var_str!(\"MCPX_SESSION\") {\n Ok(value) => value\n Err(_) => default_session\n }\n") | ||
| b.WriteString(" request = Request.from_method(Method.POST)\n .with_uri(Str.concat(endpoint, \"/v1/call\"))\n .with_body(Str.to_utf8(body))\n .add_header(\"Content-Type\", \"application/json\")\n .add_header(\"x-mcpx-session\", session)\n .add_header(\"x-mcpx-call\", session)\n") |
There was a problem hiding this comment.
Authenticate requests with the supplied daemon bearer token
When transport.bearerToken is configured, every generated Roc tool call receives HTTP 401 because the request never includes an Authorization header. The exec service already supplies MCPX_TRANSPORT_BEARER_TOKEN in scriptEnv, and daemon/bearer.go's requireBearer enforces it on every HTTP route, including /v1/call. Read that environment variable and conditionally send Authorization: Bearer <token> so Roc scripts can use authenticated daemons.
Useful? React with 👍 / 👎.
| b.WriteString("call! = |body| {\n") | ||
| b.WriteString(" endpoint = match Env.var_str!(\"MCPX_ENDPOINT\") {\n Ok(value) => value\n Err(_) => default_endpoint\n }\n") | ||
| b.WriteString(" session = match Env.var_str!(\"MCPX_SESSION\") {\n Ok(value) => value\n Err(_) => default_session\n }\n") | ||
| b.WriteString(" request = Request.from_method(Method.POST)\n .with_uri(Str.concat(endpoint, \"/v1/call\"))\n .with_body(Str.to_utf8(body))\n .add_header(\"Content-Type\", \"application/json\")\n .add_header(\"x-mcpx-session\", session)\n .add_header(\"x-mcpx-call\", session)\n") |
There was a problem hiding this comment.
Forward the run ID to preserve dry-run interception
For a Roc execution requested with dryRun:true, these requests omit X-Mcpx-Run even though the exec service supplies MCPX_RUN. In daemon/server.go, handleCall obtains the run identity exclusively from that header, and dryRunResult declines interception when the identity is empty. Consequently, Roc tool calls execute against real servers during a purported dry run, including calls with destructive side effects. Forward the run ID on every generated request so the daemon can recognize the dry-run registration.
Useful? React with 👍 / 👎.
| b.WriteString("call! = |body| {\n") | ||
| b.WriteString(" endpoint = match Env.var_str!(\"MCPX_ENDPOINT\") {\n Ok(value) => value\n Err(_) => default_endpoint\n }\n") | ||
| b.WriteString(" session = match Env.var_str!(\"MCPX_SESSION\") {\n Ok(value) => value\n Err(_) => default_session\n }\n") | ||
| b.WriteString(" request = Request.from_method(Method.POST)\n .with_uri(Str.concat(endpoint, \"/v1/call\"))\n .with_body(Str.to_utf8(body))\n .add_header(\"Content-Type\", \"application/json\")\n .add_header(\"x-mcpx-session\", session)\n .add_header(\"x-mcpx-call\", session)\n") |
There was a problem hiding this comment.
Authenticate requests with the supplied daemon bearer token
When transport.bearerToken is configured, every generated Roc tool call receives HTTP 401 because the request never includes an Authorization header. The exec service already supplies MCPX_TRANSPORT_BEARER_TOKEN in scriptEnv, and daemon/bearer.go's requireBearer enforces it on every HTTP route. Read that environment variable and attach the bearer token to generated requests.
Useful? React with 👍 / 👎.
| b.WriteString("call! = |body| {\n") | ||
| b.WriteString(" endpoint = match Env.var_str!(\"MCPX_ENDPOINT\") {\n Ok(value) => value\n Err(_) => default_endpoint\n }\n") | ||
| b.WriteString(" session = match Env.var_str!(\"MCPX_SESSION\") {\n Ok(value) => value\n Err(_) => default_session\n }\n") | ||
| b.WriteString(" request = Request.from_method(Method.POST)\n .with_uri(Str.concat(endpoint, \"/v1/call\"))\n .with_body(Str.to_utf8(body))\n .add_header(\"Content-Type\", \"application/json\")\n .add_header(\"x-mcpx-session\", session)\n .add_header(\"x-mcpx-call\", session)\n") |
There was a problem hiding this comment.
Forward the run ID so dry-run calls remain intercepted
When a Roc execution is requested with dryRun:true, the generated requests omit X-Mcpx-Run even though the exec service supplies MCPX_RUN. In daemon/server.go, handleCall obtains the run identity exclusively from that header, and dryRunResult declines interception when the identity is empty. Consequently, Roc tool calls execute against real servers during a purported dry run, including calls with destructive side effects. Forward the run ID on every generated request so the daemon can recognize the dry-run registration.
Useful? React with 👍 / 👎.
| b.WriteString(" session = match Env.var_str!(\"MCPX_SESSION\") {\n Ok(value) => value\n Err(_) => default_session\n }\n") | ||
| b.WriteString(" request = Request.from_method(Method.POST)\n .with_uri(Str.concat(endpoint, \"/v1/call\"))\n .with_body(Str.to_utf8(body))\n .add_header(\"Content-Type\", \"application/json\")\n .add_header(\"x-mcpx-session\", session)\n .add_header(\"x-mcpx-call\", session)\n") | ||
| b.WriteString(" response = Http.send!(request, {}) ? |_err| TransportError(\"mcpx daemon request failed\")\n") | ||
| b.WriteString(" if Response.status(response) < 200 or Response.status(response) >= 300 {\n return Err(StatusError(Response.status(response)))\n }\n Ok(response)\n}\n\n") |
There was a problem hiding this comment.
Return an error for tool-level failure responses
When an MCP tool returns isError:true, the daemon preserves that envelope and responds with HTTP 200 (daemon/server.go:1282), so this status-only check returns Ok(response) for a failed tool invocation. Roc callers using the generated Try result for error handling will therefore continue down the success path after a tool failure. Decode the response envelope and convert tool-level failures into Err(ToolError) rather than treating every 2xx response as success; this also preserves the result-error contract in pkgs/mcpx/AGENTS.md.
AGENTS.md reference: pkgs/mcpx/AGENTS.md:L80-L80
Useful? React with 👍 / 👎.
Closes #1964. Implements Roc codegen backend and runner support mirroring the Python implementation.
Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.